#!/usr/bin/env python
# coding=utf8

from flask import jsonify
from flask import request

from . import ext_service
from app.service.ext_service import ExtService
from app.common.exception import ServiceError

@ext_service.route("/submail", methods=["POST"])
def send_subemail():
    params = request.get_json()

    try:
        data = ExtService.send_subemail(params)
        code = 200
        status = "success"
    except ServiceError as e:
        code = e.code
        data = e.message
        status = "error"
    except Exception as e:
        code = 500
        data = e.message
        status = "error"
    finally:
        pass

    return jsonify({"code" : code, "status" : status, "data" : data})

@ext_service.route("/testa", methods=['GET'])
def test_a():

    return jsonify({"data" : "data"})
